<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      @submit.native.prevent="() => handleQuery()"
    >
      <el-form-item :label="$t('position_name')" prop="positionName">
        <el-input
          v-model="queryParams.positionName"
          :placeholder="$t('please_enter', { name: $t('position_name') })"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >{{ $t("search") }}</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{
          $t("reset")
        }}</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['position:add']"
          >{{ $t("add") }}</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table ref="multipleTable" v-loading="loading" :data="scheduleList" border :max-height="tableHeight">
      <el-table-column
        :label="$t('position_name')"
        align="center"
        prop="positionName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        :label="$t('position_code')"
        align="center"
        prop="positionCode"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        :label="$t('ranking')"
        align="center"
        prop="rankDTOList"
        :show-overflow-tooltip="true"
        :formatter="clientFormatter"
      />
      <el-table-column
        :label="$t('ranking_description')"
        align="center"
        prop="remark"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        :label="$t('action')"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            v-hasPermi="['position:view']"
            >{{$t('view')}}</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['position:update']"
            >{{$t('edit')}}</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['position:del']"
            >{{$t('delete')}}</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
      :page-sizes="[10,20,30,50,100, 200]"
    />
    <!-- 添加或修改假期对话框 -->
    <AddOrUpdata
      ref="positionDetail"
      @handleSuccesses="handleSuccess"
    ></AddOrUpdata>
  </div>
</template>

<script>
import { positionList, delPosition } from "@/api/custom/employerList";
import AddOrUpdata from "@/views/custom/position/addOrUpdata.vue";
export default {
  name: "Schedule",
  components: {
    AddOrUpdata,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 假期表格数据
      scheduleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        positionName: "",
      },

      needInfo: {},

      annualLeave: [
        {
          lengthService: null,
          vacation: null,
        },
      ],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询职位列表 */
    getList() {
      this.loading = true;
      positionList(this.queryParams).then((response) => {
        this.scheduleList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    handleSuccess() {
      this.getList();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        positionName: null,
        vacationCode: null,
        vacationType: null,
        remark: null,
        statutoryHoliday: null,
        paidVacation: null,
        scheCondition: null,
        sex: null,
        maritalStatus: null,
        minimumLeaveUnit: null,
        leaveTime: null,
        maximumApplication: null,
        enableLeaveLimit: null,
        libertyDay: null,
        annualCycle: null,
        sabbaticalDay: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        sectionId: null,
        distribution: null,
        allocationDate: null,
        rule: null,
        lengthService: null,
        vacation: null,
        lineLimit: null,
        validity: null,
        full: null,
        percent: null,
        vacationMonth: null,
        vacationDay: null,
        advance: null,
      };
      this.lookView = false;
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      let detailParams = {
        item: {},
        title:this.$t('add'),
        lookView: false,
      };
      this.$refs.positionDetail.showDateschedule(detailParams);
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      let detailParams = {
        item: { ...row },
        title:this.$t('edit'),
        lookView: false,
      };
      this.$refs.positionDetail.showDateschedule(detailParams);
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.reset();
      let detailParams = {
        item: { ...row },
        title:this.$t('view'),
        lookView: true,
      };
      this.$refs.positionDetail.showDateschedule(detailParams);
    },
    clientFormatter(item) {
      if (item.rankDTOList && item.rankDTOList.length) {
        let name = item.rankDTOList.map((element) => {
          return element.rankName;
        });
        if (name && name.length) {
          return name.join(",");
        }
      } else {
        return "--";
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id;
      this.$modal
        .confirm(this.$t('delete_data'))
        .then(function () {
          return delPosition(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess(this.$t('operation_successful'));
        })
        .catch(() => {});
    },
  },
};
</script>
